package priv.mill.controller;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;

import priv.mill.model.Book;

@Controller
@RequestMapping("books")
@SessionAttributes(names= {"books"},types= {ArrayList.class})
public class BooksController {
	
	private Logger logger = LoggerFactory.getLogger(BooksController.class);
	
	private static List<Book> books=new ArrayList<>();
	{
		books.add(new Book("神雕侠侣",89.7,"渣渣"));
		books.add(new Book("绝代双骄",109.7,"古龙"));
		books.add(new Book("隋唐英雄传",129.7,"黄易"));
	}
	@GetMapping("all")
	public String findAll(Map<String,Object>map) {
//		debug
//		info
//		warning
//		error
		logger.error("这就是我写出的日志！");
		map.put("books",books);
		return "bs/books";
	}
	@GetMapping("del")
	public String del (@RequestParam("name")String name) {
		books.remove(new Book(name,0,null));
		return "redirect:all";
	}
	@GetMapping("add")
	public String add(String name,double price,String auth ) {
		books.add(new Book(name,price,auth));
		return "redirect:all";
	}
//	@GetMapping("select")
//	public String select(String name) {
//		books.
//	}
}
